﻿using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using UnityEngine;

namespace U3DUtility
{
    public class Utils
    {
        /// <summary>
        /// 输入值从一个区间对应到另一个区间
        /// </summary>
        /// <param name="value"></param>
        /// <param name="InFrom"></param>
        /// <param name="InEnd"></param>
        /// <param name="OutFrom"></param>
        /// <param name="OutEnd"></param>
        /// <returns></returns>
       static public float MapRangeClamp(float value, float InFrom, float InEnd, float OutFrom, float OutEnd)
        {
            value = Mathf.Clamp(value, InFrom, InEnd);
            float InLength = Mathf.Abs(InEnd - InFrom);
            float LengthValueToFrom = Mathf.Abs(value - InFrom);
            float curPercent = LengthValueToFrom / InLength;
            //Debug.Log(curPercent);

            float ff = OutFrom + (OutEnd - OutFrom) * curPercent;
            //Debug.Log(ff);
            return ff;
        }

        /// <summary>
        /// 判断字符串全部是否是中文。返回true 则表示含有非中文
        /// </summary>
        /// <param name="str_chinese"></param>
        /// <returns></returns>
        static public bool IsChinese(string str_chinese)
        {
            bool b = false;
            for (int i = 0; i < str_chinese.Length; i++)
            {
                Regex reg = new Regex(@"[\u4e00-\u9fa5]");
                if (!reg.IsMatch(str_chinese[i].ToString()))
                {

                    b = true;
                    break;
                }
            }

            return b;

        }
    }
}
